package com.dlwx.firefighting.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dlwx.firefighting.R;
import com.dlwx.firefighting.bean.AddressBean;
import com.dlwx.firefighting.config.Constant;
import com.dlwx.firefighting.utils.DialogUtils;
import com.dlwx.firefighting.utils.SPUtils;


/**
 * 收货地址adapter
 */

public class AddressListAdapter extends ListBaseAdapter<AddressBean> {

    private Context context;
    private int selectItem = 0;
    public int getSelectItem() {
        return selectItem;
    }
    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    public AddressListAdapter(Context context) {
        super(context);
        this.context=context;
    }

    @Override
    public int getLayoutId() {
        return R.layout.address_list_item;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        AddressBean bean = mDataList.get(position);

        ImageView imageView = holder.getView(R.id.address_item_select);
        TextView tv_name = holder.getView(R.id.address_item_name);
        TextView tv_phone = holder.getView(R.id.address_item_phone);
        TextView tv_address = holder.getView(R.id.address_item_address);
        TextView tv_delete = holder.getView(R.id.tv_delete);
        tv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtils.getMaterialDialogTwoBtn(context,"","确认要删除该地址吗？").show();
            }
        });
            tv_name.setText("姓名："+bean.getConsignee());
            tv_phone.setText("手机："+bean.getMobile());
            tv_address.setText("地址："+bean.getAddress());
        if(bean.is_default()){
            imageView.setVisibility(View.VISIBLE);
            SPUtils.put(context, Constant.ADDRESS_DEFAULT,bean.getAddress_id());
        }else{
            imageView.setVisibility(View.INVISIBLE);

        }


    /*    if (!TextUtils.isEmpty(bean.consignee_address)) {
            if (position == 0) {
                SpannableStringBuilder builder = new SpannableStringBuilder("[默认地址]" + bean.consignee_address);
                ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
                builder.setSpan(redSpan, 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                tv_address.setText(builder);
            } else {
                tv_address.setText(bean.consignee_address);
            }

        } else {
            tv_address.setText("");
        }

        if (position == selectItem) {
            imageView.setImageResource(R.mipmap.select_box_yes);
        } else {
            imageView.setImageResource(R.mipmap.select_box_no);
        }
*/

    }

}
